package com.lsw.jgyf.ui.activity;

import android.webkit.WebView;

import com.lsw.jgyf.R;
import com.lsw.jgyf.ui.base.activity.TitleBarActivity;
import com.lsw.util.StringUtil;

import butterknife.BindView;

import static com.lsw.util.StringUtil.web;

/**
 * Created by Administrator on 2018/7/24 0024.
 */

public class WebviewActivity extends TitleBarActivity {

    @BindView(R.id.webview)
    WebView webview;
    String url, title;

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initEventAndData() {
        webview.getSettings().setJavaScriptEnabled(true);
        url = getIntent().getStringExtra("url");
        title = getIntent().getStringExtra("title");
        tvTitle.setText(title);
        if (!StringUtil.isNullOrEmpty(url)) {
            if (url.startsWith("http")) {
                webview.loadUrl(url);
//                webview.setWebChromeClient(new WebChromeClient() {
//                    @Override
//                    public void onReceivedTitle(WebView view, String title) {
//                        super.onReceivedTitle(view, title);
//                        if (!StringUtil.isNullOrEmpty(title))
//                            tvTitle.setText(title);
//                    }
//                });
            } else {
                webview.loadDataWithBaseURL(null, web + url, "text/html", "utf-8", null);
            }
        }

    }

    @Override
    protected int setContentLayoutView() {
        return R.layout.activity_webview;
    }

    @Override
    protected void setActionBarDetail() {

    }
}
